package com.lvmama.rhino.common.utils.spark

import org.apache.spark.SparkConf
import org.apache.spark.sql.SparkSession

/**
  * Created by yuanxiaofeng on 2017/3/15.
  */
trait StructuredStreamingApplication {
  var appName: String

  var sparkConfig: Map[String, String]

  def streamingBatchDuration: Long

  def streamingCheckpointDir: String

  def withStructuredApplication(f: SparkSession => Unit): Unit = {
    val conf = new SparkConf()
    sparkConfig.foreach{case (k, v) => conf.setIfMissing(k, v)}
    val spark = SparkSession
                  .builder()
//                  .master("local[3]")
                  .appName(appName)
                  .config(conf)
                  .getOrCreate()

    f(spark)
  }
}
